import { PageSelecter } from "./PageSelecter";
import { GTileList } from "../../../../../com/mui/controls/GTileList";
import { ObjCreate } from "../ObjCreate";
import { GBoxDirection } from "../../../../../com/mui/containers/globalVariable/GBoxDirection";
import { ScrollPolicy } from "../../../../../fl/controls/ScrollPolicy";
import { PageItemRenderer } from "../renderers/PageItemRenderer";
import { DataProvider } from "../../../../../fl/data/DataProvider";
type int = number;
//class PageSelectCenter
    
    export  class PageSelectCenter /* flash.display.Sprite */
    {
        constructor(arg1: int=4, arg2: Boolean=false, arg3: int=-1, arg4: Object=null, arg5: PageSelecter=null)
        {
            
            this._pageSize = arg1;
            this._isShowNull = arg2;
            this._nullValue = arg3;
            this.initPageSelector(arg5);
            this.initList(arg4);
            this._pageSelecter.addEventListener(flash.events.Event.CHANGE, this.pageChangeHandler);
            return;
        }

        public updateData(arg1: Array<any>): void
        {
            this._data = arg1;
            if (arg1 != null) 
            {
                this._pageSelecter.maxPage = Math.ceil(arg1.length / this._pageSize);
            }
            this._pageSelecter.currentPage = 1;
            this.pageChangeHandler(null);
            return;
        }

        public get list(): GTileList
        {
            return this._list;
        }

        public get pageSelecter(): PageSelecter
        {
            return this._pageSelecter;
        }

        /* internal  */initPageSelector(arg1: PageSelecter=null): void
        {
            if (arg1 != null) 
            {
                this._pageSelecter = arg1;
                this.addChild(this._pageSelecter);
                return;
            }
            this._pageSelecter = new PageSelecter();
            this.addChild(this._pageSelecter);
            this._pageSelecter.mode = PageSelecter.SingleMode;
            this._pageSelecter.move(42, 53);
            this._pageSelecter.maxPage = 1;
            this._pageSelecter.currentPage = 1;
            return;
        }

        /* internal  */initList(arg1: Object): void
        {
            this._list = ObjCreate.createTileList(0, 0, 160, 34, this);
            this._list.direction = GBoxDirection.HORIZONTAL;
            this._list.rowCount = 4;
            this._list.columnWidth = 36;
            this._list.horizontalGap = 4;
            this._list.scrollPolicy = ScrollPolicy.OFF;
            if (arg1 != null) 
            {
                this._list.setStyle("cellRenderer", arg1);
            }
            else 
            {
                this._list.setStyle("cellRenderer", PageItemRenderer);
            }
            return;
        }

        /* internal  */pageChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            if (this._data == null) 
            {
                return;
            }
            var loc1=this._pageSelecter.currentPage;
            var loc2=(loc1 - 1) * this._pageSize;
            var loc3=new DataProvider();
            var loc4=loc2;
            while (loc4 < loc2 + this._pageSize) 
            {
                if (loc4 >= this._data.length) 
                {
                    if (this._isShowNull) 
                    {
                        loc3.addItem(this._nullValue);
                    }
                }
                else 
                {
                    loc3.addItem(this._data[loc4]);
                }
                ++loc4;
            }
            this._list.dataProvider = loc3;
            this._list.drawNow();
            return;
        }

        /* internal */ /* var */_pageSelecter: PageSelecter;

        /* internal */ /* var */_list: GTileList;

        /* internal */ /* var */_pageSize: int;

        /* internal */ /* var */_data: Array<any>;

        /* internal */ /* var */_dataProvider: DataProvider;

        /* internal */ /* var */_isShowNull: Boolean;

        /* internal */ /* var */_nullValue: int;
    }
